﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Hang.Blog.Helper;
using Hang.Blog.Inter;

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;

using Snowflake.Core;

namespace Hang.Blog.Imp {
    /// <summary>
    /// 上传文件
    /// </summary>
    [Route(StringConsts.Api + "file/")]
    public class FileAppService : BlogAppService, IFileAppService {
        private readonly IConfiguration _configuration;
        //用Guid可能查不出来
       

        public FileAppService(IConfiguration configuration) {
            _configuration = configuration;

        }


        /// <summary>
        /// 上传附件
        /// </summary>
        /// <param name="file">文件</param>
        /// <param name="dire">文件分类</param>
        /// <returns></returns>
       
        [HttpPost]
        [Route("upload")]
        public string Upload(IFormFile file, string dire) {
            var worker = new IdWorker(1, 1);
            var result = FileHelper.SaveFile(file, dire, worker.NextId(), _configuration["App:SelfUrl"]);
            return result;
        }
    }
}
